import { getOrderProduct } from '@/api/order'
import _ from 'lodash'
import { ref } from 'vue'

export default () => {
  const goods = ref<Array<OrderGood>>([])
  const goodsTotal = ref(0)
  const getGoodsParam = ref({
    brandId: '',
    keyword: '',
    limit: 50,
    page: 1,
    typeId: '',
    typeThreeId: '',
    typeTwoId: '',
  })
  const getGoodsLoading = ref(false)

  const getGoods = async () => {
    getGoodsLoading.value = true
    const res = await getOrderProduct(getGoodsParam.value)
    getGoodsLoading.value = false
    if (res.data.success) {
      goods.value = _.cloneDeep(res.data.data.rows)
      goodsTotal.value = Number(res.data.data.total)
    }
  }

  return {
    goods,
    goodsTotal,
    getGoodsParam,
    getGoodsLoading,
    getGoods,
  }
}
